Firefly swarm intelligence based cooperative localization and automatic clustering for indoor FANETs

At present, the applications of multiple unmanned aerial vehicles (UAVs) are becoming more and more widespread, covering many civil and military fields. When performing tasks, UAVs will form a flying ad hoc network (FANET) to communicate to each other. However, subject to high mobility, dynamic topology, and limited energy of FANETs, maintaining stable communication performance is a challenging task. As a potential solution, the clustering routing algorithm divides the entire network into multiple clusters to achieve strong network performance. Meanwhile, the accurate localization of UAV is also strongly required when FANETs are applied in the indoor scenario. In this paper, we propose a firefly swarm intelligence based cooperative localization (FSICL) and automatic clustering (FSIAC) for FANETs. Firstly, we combine the firefly algorithm (FA) and Chan algorithm to better cooperative locate the UAVs. Secondly, we propose the fitness function consisting of link survival probability, node degree-difference, average distance, and residual energy, and take it as the light intensity of the firefly. Thirdly, the FA is put forward for cluster-head (CH) selection and cluster formation. Simulation results indicate that the proposed FSICL algorithm achieves the higher localization accuracy faster, and the FSIAC algorithm achieves the higher stability of clusters, longer link expiration time (LET), and longer node lifetime, all of which improve the communication performance for indoor FANETs.

UAVs, but also considers the CH selection and flight trajectories of UAVs for building clusters with more stable intra-cluster communication in a 3-D area.
The main contributions of this paper are summarized as follows: 1. Aiming at the problem of inaccurate indoor GPS localization, we combine the computing ability of the Chan algorithm and the swarm search ability of the FA to locate UAVs more accurately. The first solution of location is obtained by the Chan algorithm, the FA then is used to obtain a more accurate solution in the limited cube search zone centered on the first solution; 2. Considering the high mobility, dynamic topology and limited energy of UAVs in FANETs, we formulate a more reasonable fitness function consisting of link survival probability, node degree-difference, average distance and residual energy for the CH selection; 3. Inspired by the social behavior of fireflies, we take the fitness value of the UAV as the light intensity of the firefly, and the UAV with highest light intensity in the cluster is selected as the CH. Then the FA is employed to spontaneously generate optimized clusters for robust transmission which allows CMs adjust their locations on the basis of their fitness values to automatically track the motion of CHs in the UAV swarm, which makes the topology within the cluster more stable; 4. Extensive simulation results verify the network performance gains of the proposed scheme compared with several existing algorithms. Specifically, the proposed FSICL algorithm estimates locations of UAVs more accurate in less time. With the help of the accurate localization, FSIAC algorithm achieves the higher cluster stability, longer LET, and longer node lifetime. All simulation results prove that the proposed FSICL and FSIAC algorithms could be utilized in practice as a new localization and clustering algorithm respectively for indoor FANETs.
The rest of this article is organized as follows. In Section "Related work", we analyze the related work. In Section "Preliminaries", we present the system model, FA, UWB localization and Chan algorithm. In Section "Proposed algorithms", we introduce our proposed FSICL and FSIAC algorithms in detail. In Section "Simulation results", we present the performance evaluation results for the proposed algorithms. Finally, we conclude the paper in Section "Conclusion".

Related work
Ultra wideband (UWB) is one of the most popular technologies adopted for indoor localization. In UWB localization systems, the time difference of arrival (TDOA) is usually used as it does not directly use the arrival time of the signal, but uses the time difference of the signals received by multiple base stations to determine the location of the mobile station. Compared with the time of arrival (TOA) algorithm, significantly fewer communications are required to complete a localization, and the localization accuracy is also improved [15][16][17].
The core of localization based on TDOA is to solve the nonlinear localization equations and there were three main methods researched, the first is analytical method, such as Fang algorithm [18] and Chan algorithm [19]; the second is iterative method, such as Taylor algorithm [20]; the third is intelligent method, such as particle swarm optimization (PSO) algorithm [21]. Among them, the Fang algorithm obtains the location of the unknown UAV by linearizing the hyperbola with the help of three and only three base stations. The Chan algorithm obtains the location by solving the non-recursive hyperbolic equation, and localization accuracy increases with the increase of base stations. However, for measurements with large errors in the real environment, such as in the presence of non-visual propagation, this algorithm's performance is significantly degraded. The above two analytical algorithms have the advantages of simple principle and low computational complexity. As an iterative method of Taylor algorithm, it obtains the initial iteration value based on Taylor series expansion to perform least squares estimation, and then the local least squares solution of the location estimation error is solved to update the location of the UAV. The disadvantage of this algorithm is that it is computationally intensive and easily to fall into the local minimum if the initial target location is poorly chosen. Compared with the above two mathematical methods, the PSO algorithm can calculate the location faster and is less affected by noise, but it also faces the problem of easily falling into the local optimum.
Based on the good performance of localization, the clustering routing algorithm can be deployed to better manage the network topology. There were various typical clustering algorithms proposed in the literature, e.g. the lowest-ID clustering algorithm (LIC) [22], the highest-connectivity clustering algorithm (HCC) [23] and the weight-based clustering algorithm (WCA) [24]. In the LIC, each UAV in the network corresponds to a unique ID number, and the UAV with the smallest ID number among the adjacent UAVs will be selected as the CH. Different from the LIC, the HCC is clustered based on the degree of connectivity. By calculating the number of neighbor UAVs, the UAV with the largest number of neighbor UAVs is selected as the CH. In comparison to the LIC and HCC algorithms, the WCA algorithm does not consider a single factor, but integrates multiple factors together, such as node degree, mobility, residual energy, distance from neighbor UAVs. In this way, it can better adapt to different scenarios. An energy and mobility-aware stable and safe clustering (EMASS) algorithm was proposed based on the WCA in [25], which considers three parameters of mobility, stability, and safety to provide stable routing and efficient data collection in FANETs. However, the computation process takes too long and does not take into account the node degree.
Several swarm intelligence and machine learning-based clustering schemes were also proposed in recent years. An improved grey wolf based clustering optimization algorithm (GWCOA) was proposed in [26]. It imitates the leadership hierarchy and hunting mechanism of grey wolves to create efficient clusters. However, the parameter of link quality in the fitness function for CH selection is not considered in this paper. A clustering strategy was presented by [27], which uses the K-means algorithm to quickly cluster the entire network, and then implement a CH selection algorithm based on deep Q-learning (DQN) in each cluster. In this paper, the reinforcement learning is used to adaptively to select the most appropriate CH, but the authors allocates the clusters manually without considering automatic clustering. A bio-inspired mobility-aware clustering (BIMAC) algorithm was proposed in [28], which ameliorates the model of physarum polycephalum for CH selection to adapt to mobile ad hoc networks. The algorithm combines with the mobility characteristics of UAVs, so it can effectively establish and maintain clusters, and improves the average LET and average CH holding time. But the algorithm does not take into account the flight trajectories of UAVs. In [29], an intelligent clustering routing approach (ICRA) algorithm was proposed which takes four factors into account to calculate the utility of a UAV, including the residual energy of the UAV, the degree centrality of the UAV, the velocity similarity, and the link holding time. The reinforcement learning was utilized to help clustering strategy adjustment module learn the benefits brought by adopting different strategies to calculate the UAVs utility in a specific network state and determine the optimal clustering strategy accordingly. However, the authors does not consider the trajectories of CMs, which may cause the UAVs acting as CMs to change too fast and the topology of the intra-cluster to be unstable.
In this paper, inspired by the swarm intelligence algorithms proposed in [30][31][32][33][34], we propose FSICL and FSIAC algorithms to make UAV localization more accurate and communication of UAV swarm more stable. Compared with several algorithms, the proposed algorithms estimates locations of UAVs more accurately, and achieves the higher cluster stability, longer LET, and longer node lifetime in the indoor FANET.

System model
For a scenario of target resuce, we consider a typical network model deployed by N small random moving UAVs with different battery power flying at different altitudes and 1 ground station (GS) shown in Fig 1. All UAVs are equipped with long-distance and short-distance wireless communication protocols. To improve the dynamic network performance, the UAVs are organized into several clusters, and each cluster is composed of a CH and CMs. CHs work in 2.4GHz frequency band and are responsible for intra-communication and inter-communication, while CMs work in 5GHz frequency band and only need to complete the intra-cluster communication. The task of the UAV swarm is to search the indoor area and transmit information of the target person back to the GS through single/multi-hop routing on the premise of ensuring the communication quality.
We define that UAVs in the communication range R form a cluster. All UAVs are equipped with UWB localization system and aware of locations of themselves and neighbors by sending Hello message to their neighbor UAVs within R after every T seconds period.

Firefly algorithm
In our work, the FA is first considered as it is a novel swarm intelligence method. The FA is proposed by [34] as a heuristic algorithm inspired by the blinking behavior of fireflies. The main purpose of a firefly's flash is to act as a signaling system to attract other fireflies.
The firefly with the higher luciferin is brighter than others, and therefore, has the higher light intensity. Each firefly will move towards a brighter one within its vision range (i.e., communication range) R, which is set according to the maximum communication radius of the UAV. Thus, if two fireflies are far apart, the brighter firefly will not attract the darker one, which leads to the fact that the entire swarm can automatically divide into several clusters and the darker fireflies will track the brighter fireflies. It is similar to the case that UAVs need to gather around the CHs to form stable clusters. If the swarm size is much larger than the number of clusters, this enables all UAVs to efficiently find both global and local optimums simultaneously, where the global optimum is the optimum of all the local optimums.
In the simplest case for maximum optimization problems, the light intensity I of a firefly at a particular location x can be chosen as I(x(t)) / f(x(t)), where f(�) is objective function value at t time. Attractiveness β of firefly n can be defined as: where d nm is the distance from firefly n to firefly m, β 0 is the attractiveness at r = 0. μ is a fixed light absorption coefficient. For instance, the distance between any two fireflies n and m at their respective locations x n = (x n , y n , z n ) and x m = (x m , y m , z m ), is the Cartesian distance: ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi where x n , y n , z n is the 3-D coordinates of the nth firefly. Firefly n will move in the direction of other fireflies m that are brighter than it: where the second term is due to the attraction while the third term is randomization with λ being the randomization parameter. rand is a random number generator uniformly distributed in [0, 1]. It should be noticed that when μ equals 0, the FA is the same as the PSO, and when μ equals 1, the FA is the same as random search algorithm. The biggest difference between the FA and PSO is that the FA can find the global optimum and local optimums at the same time, and it is more difficult to fall into the local optimum. In the cluster, each CH represents a local optimum which allows their CMs to automatically follow to perform the task. This mechanism considers the flight trajectories of UAVs and its benefit is that it builds a more stable topology within the cluster and thus achieve the more stable intra-cluster communication. Therefore, the FA with these characteristics is more suitable for simulating the clustering process in FANETs.

UWB localization based on TDOA
Due to the high data transmission rate (up to 1Gbit/s), strong anti-multipath interference ability, and low power consumption, UWB communication becomes one of the most popular technologies adopted for indoor localization. TDOA is one of the common localization methods which can achieve centimeter-level localization accuracy. In a UWB localization based on TDOA system for UAV swarm, a number of spatially separated receivers (i.e., anchors) capture the UWB signals emitted by the UAV with UWB sensors and estimate TDOAs to locate the UAV (i.e., tag) in an indoor environment.
The basic principle of TDOA algorithm is to firstly measure the arrival time difference between the UAV signal to each known anchor, then multiply the electromagnetic wave propagation speed to obtain the distance difference with which some hyperbola equations are constructed.
Assume there are A anchors placed in a 3-D localization zone, the location of the anchor i is x a i ; i ¼ 1; 2; :::AðA � 4Þ, and the location of the UAV is x n . The UAV sends a UWB signal once in a 3-D indoor area, and all anchors within the UAV localization distance receive the wireless signal. R i is the distance from the UAV to the anchor i, and R i is defined as: ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi R i,1 represents the difference between the distance from the UAV to anchor 1 and to anchor i: where s stands for the speed of UWB radio wave, τ i,1 stands for the TDOA from the UAV to anchor 1 and anchor i, and r i,1 is the additive white gaussian noise (AWGN) with zero-mean and variance η = E[|r i,1 | 2 ] = σ 2 . Based on Eqs (4) and (5), we can get: (6) gives the location of the UAV which is not an easy task because the equations involved are nonlinear. The Chan algorithm is one of the methods to tackle this problem.

Chan algorithm
The Chan algorithm uses the weighted least squares (WLS) method twice to solve the Eq (6), in which the initial nonlinear equations are converted into linear equations with relevant TDOA data firstly, then the first WLS gives an initial solution, and the second WLS makes use of the known constraint between the UAV coordinates and the extra variable, gives an improved location estimate. For more specific calculation results and formula derivation, please refer to [19].
In general, the Chan algorithm is a typical localization algorithm which has high localization accuracy when the TDOA error obeys the Gaussian distribution and the variance of noise is small.

Firefly swarm intelligence based cooperative localization
At present, the most commercially available UAV localization method is GPS [35]. This commonly used localization method has high localization accuracy in an outdoor unobstructed environment, but it is susceptible to interference and the signal is unstable in a more complex indoor environment. Therefore, a stable localization method is needed to more accurately locate the UAV indoors.
As analyzed in the last section, the Chan algorithm is a typical localization algorithm which has high localization accuracy when the TDOA error obeys the Gaussian distribution and the variance of noise is small. However, due to the complexity of the indoor environment and the nonlinear problem of localization estimation, the Chan algorithm has a large error when noise power is large.
The TDOA estimation problem is a nonlinear and non-convex optimization problem as well. As a random search algorithm of SI, the FA is simple in principle and easy to implement which is an effective method for solving nonlinear equations. However, the FA is prone to fall into the local optimum solution and premature convergence.
In this paper, we utilize their respective advantages and propose a cooperative localization based on the Chan algorithm and FA to obtain more precise locations of UAVs.
The maximum likelihood method is used to estimate the coordinates of the UAV (x n , y n , z n ). We set the TDOA vector is τ = [τ 2,1 , τ 3,1 , � � �, τ A,1 ] T , which obeys the A−1 dimensional Gaussian distribution, and the distance mean vector is: The actual distance vector r from UAV to anchor i and the actual distance vector r 1 from UAV to anchor 1 are set as r = [r 2 , r 3 . � � �,r A−1 ] T and r 1 = [r 1 , r 1 . � � �,r 1 ] T respectively. According to the previous assumptions, The variables in ΔR are independent identically distributed Gaussian random variables with a mean value of r i − r 1 .
Therefore, we have the likelihood function: where σ is the variance of additive white gaussian noise (AWGN). Thus, the estimated location closest to the actual location is equal to the coordinates value that maximizes the likelihood function for the FA: We can see this equation is a very complex nonlinear function, and the maximum likelihood estimate can be obtained by searching the coordinates of the UAV corresponding to the minimum value of this function, but the computation of direct search is very high. Therefore, we use the FA to search the optimal solution in the whole potential solution space to determine the location of the UAV, taking advantage of the fact that the FA basically has no restriction on the optimization function [34].
Combining the computational ability of the Chan algorithm and the swarm search ability of the FA, we propose a cooperative localization algorithm as shown in Fig 2. The first solution is obtained by the Chan algorithm, the FA then is used to obtain a more accurate solution in the limited cube search zone centered on the first solution. Since each firefly in the space represents a localization estimation and search zone is narrowed, the probability of the FA falling into the local optimum solution is reduced, the convergence speed is raised, and the localization accuracy is increased. The process of cooperative localization algorithm is described as follows: 1. The first solution x c n =(x c n , y c n , z c n ) is calculated by the Chan algorithm, and the R c i;1 from the solution to each anchor is obtained, which is defined as: ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ðx i À x c n Þ 2 þ ðy i À y c n Þ 2 þ ðz i À z c n Þ 2 q À ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi We define the difference between R i1 À R c i1 for the Chan algorithm as: 2. A search zone that is too small may cause the UAV solution to be excluded from the space, while a search zone that is too large will increase the search time and be more likely to fall into a local optimum solution. Based on the change of α as shown in Fig 3, we can infer that the distance between the estimated location and the actual location of the UAV is less than αγ, where γ is the empirical coefficient. Thus, we then set up a cube search zone with side length 2αγ centered on the first solution x c n for firefly swarm search, and the TDOA R f i;1 from the solution x f n ¼ ðx f n , y f n , z f n ) obtained by the FA to each anchor is obtained, which is defined as: We define the difference between R i;1 À R f i;1 for the FA as:

PLOS ONE
Cooperative localization and automatic clustering for indoor FANETs

Firefly swarm intelligence based automatic clustering
For a large-scale, high-speed FANET, clustering is one of the effective methods for UAV topology control. The process of CH selection and cluster formation are key steps to stabilize network structure, improve communication reliability, and increase UAV lifetime. In this section, we analyze and describe the proposed FSIAC clustering algorithm, including CH selection and clusters formation. Cluster head selection. Aiming at the characteristics of FANETs, we propose a fitness function consists of four parameters, namely the link survival probability, node degree-difference, average distance, and residual energy for CH selection. In order to obtain the fitness value, the UAV will send the Hello message containing the location, velocity information to their neighbor UAVs within R.
• Link survival probability Based on the highly dynamic topology of the network, the link survival probability is proposed to better describe the mobility of UAVs.
With the help of the accurate location obtained by the FSICL algorithm, the current UAV n receives the Hello message containing the location and velocity information sent by its neighbor UAV m twice consecutively within the period time T from location b to location c, location d is the relative location of m to n, and we assume that within T, the relative moving speed and direction of the UAV remain unchanged.
The movement speed of the UAV m can be obtained by Eq (14): where cosa ¼ x n ðt þ TÞ À x n ðtÞÞ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ðDx n 2 À ðz n ðt þ TÞ À z n ðtÞÞ 2 Þ q ð16Þ cosb ¼ ðy n ðt þ TÞ À y n ðtÞÞ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ðDx n 2 À ðz n ðt þ TÞ À z n ðtÞÞ 2 Þ q ð17Þ cosg ¼ ðz n ðt þ TÞ À z n Þ Dx n ð18Þ Similarly, the movement speed of the UAV n can also be obtained: Accordingly, the relative speed between UAV m and n can be expressed as: Then coordinates of location e is: v nm can be seen as the direction vector of the line fg, then we can calculate the lengths of line de and eg respectively as: ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ag 2 À ae 2 p ¼ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi We define the change of distance difference between UAV m and n in period T as: In the approaching and leaving models as shown in Fig 5, we can find out Δd nm < 0 in the approaching model, while Δd nm > 0 in the leaving model.
The link survival probability between UAV n and m is related to the relative speed and the distance between them. Therefore, the link survival probability can be expressed as: where t max is the normalization factor which is defined as: Consequently, the total link survival probability of UAV n can be obtained: The bigger the link survival probability, the more stable the network topology, and the lower CHs update frequency. Therefore, UAV n with a bigger W 1 n is more likely to be selected as a CH.
• Node degree-difference Each UAV acts as a node in the FANET, and due to the limited network bandwidth resources, the number of UAVs in a cluster should be controlled. A large node degree reduces the number of clusters, but it may cause network congestion and affect service quality, while a small node degree causes a serious waste of valuable network bandwidth resource. In the network, the node n can transmit Hello message to its neighbors to obtain the node degree, which is defined as: The optimal number of UAVs in a network is affected by the intra-cluster and inter-cluster communication bandwidth and the number of UAVs in the entire network. According to [36], let B 1 represent the bandwidth of intra-cluster communication, B 2 represent the bandwidth of inter-cluster communication, the optimum number of UAVs in a cluster is: The node degree-difference of UAV n is the degree of similarity between the actual node number and the theoretical optimal node number, which is defined as: The parameter W 2 n is defined as: UAV n with a bigger W 2 n is more likely to be selected as a CH. • Average distance Since the FANET is a dynamic network, and the distance between UAVs is constantly changing. When two UAVs are far apart, the connection between them is unreliable, so the average distance between UAVs is one of the factors that should be considered. The average distance between UAV n and all its neighbor UAVs Distance n as: The parameter W 3 n is defined as: UAV n with a bigger W 3 n is more likely to be selected as a CH. • Residual energy This paper proposes the calculation method of UAV residual energy, considering the influence of node degree on energy consumption when the node acts as a CH and a CM at different speed, making the calculation method more reasonable. Assuming that the initial energy of the UAV n is E, the residual energy is W 4 n . When the UAV acts as a CM, the energy consumed per node degree per unit time is e 1 , and when it acts as a CH, the energy consumed per node degree per unit time is e 2 , and when it is hovering, the energy consumed per unit time is e h , then the residual energy of the UAV n after a period of time is: where i is the number of times the UAV n acts as a CM, Degree ni is the node degree of the UAV n is acting as a CM for the i-th time, t i is the time during the UAV acts as a CM for the ith time. j is the number of times the UAV acts as a CH, Degree nj is the node degree of the UAV n is acting as a CH for the j-th time, t j is the time during the UAV acts as a CH for the j-th time, t h is the hovering time of UAV, G n is the weight of UAV n.
As a special node in the cluster, the CH not only consumes the energy to process the data of CMs uploaded in the cluster, but also undertakes the heavy data transmission task. Compared to the CH, the CM only needs less power to send data to the CH that are closer, not to the GS that may be farther away. Therefore, The higher the residual energy of UAV n, the more reasonable it is to be selected as a CH.
• Fitness function Eventually, based on the preceding discussions, the link survival probability W 1 n , the node degree-difference W 2 n , the average distance W 3 n and the residual energy parameter W 4 n of UAV n of the UAV can be obtained, and known by all neighbors. Combining these four parameters, a fitness function can be formed as the light intensity I n in the proposed clustering algorithm and the UAV n is selected as a CH with the highest fitness value, which is described as: where w 1 , w 4 , w 3 , w 4 are the weights of 4 parameters respectively, and w 1 + w 2 + w 3 + w 4 = 1. Their values can be determined according to the task. In this paper, we treat the 4 parameters as equally important, i.e., w 1 =w 4 =w 3 =w 4 =0.25. Cluster formation. In the FANET, the fast UAV movement makes UAVs to join or leave the clusters frequently, which is more likely to cause greater routing overhead and increase computing load. Cluster formation of FSIAC is performed to add new UAVs, delete UAVs and change the CHs where every UAV is treated as a firefly. A darker UAV tracks a brighter UAV within its field of view, which causes the whole UAV swarm to be automatically divided into several clusters. The light intensity of each UAV updates based on the fitness function, and CH manages the cluster by receiving the location and velocity information of all UAVs within the communication range and constantly updating the topology table. CMs need to adjust their locations spontaneously to track the motion of the CH, thus prolonging the CH holding time and reducing the CH handover rate, improving the clustering stability. Algorithm 2 shows the proposed FSIAC algorithm with O(MaxIteration * N * M n ) computational complexity, and the flowchart of this algorithm is shown in Fig 6. for n = 1: N 8: Calculate fitness function I n using Eq (34) 9: for m = 1: M n 10: Calculate fitness function I m using Eq (34) 11: if (I n � I m ) 12: UAV n declares itself as a CH through a Hello message and UAV m moves towards UAV n. 13: else, UAV m declares itself as a CH through a Hello message and moves by the task. 14: end if 15: Update location and evaluate new fitness value 16: end for m 17: end for n 18: end while

Simulation results
In this section, the performance of the proposed FSICL and FSIAC algorithms are evaluated via simulation in Matlab (R2021b) in a 64-bit computer with a AMD Ryzen R5 3400G processor and 16 GB RAM. Table 1 lists out main simulation parameters. We can see that there are five UAVs with large localization error by the Chan algorithm while there is only one UAV with large localization error by FSICL. In this case, the proposed FSICL algorithm has higher localization accuracy than the Chan algorithm.
Convergence. Fig 9 shows the proposed FSICL converges to a bigger fitness value faster the Chan algorithm and PSO, which means the proposed FSICL uses less time to get a more accurate location of the UAV than the Chan algorithm and PSO. This is because the FSICL works in the smaller space around the first estimated location by the Chan algorithm, which helps to narrow search zone and search time of the FA. It should be noted that, the fitness values obtained by the FA and PSO are smaller than that obtained by the FSICL, which can be explained as that both the FA and PSO algorithms converge to their local optimums. Furthermore, the value obtained by the PSO is smaller than that obtained by the FA, which represents the FA is less likely to fall into the local optimum than the PSO due to its advantage of finding both the global optimum and the local optimums. Root mean square error. Fig 10(a) shows the average root mean square error (RMSE) varies with the variance of measurement noise. RMSE is a measure of the deviation between the estimated location and actual location. The lower the RMSE, the higher the localization accuracy. We can see that RMSEs of all localization algorithms increase with the increase of measurement noise. In these algorithms, the proposed FSICL achieves the lowest RMSE. This is because the proposed FSICL algorithm directly searches for the solution of Eq (9) from the maximum likelihood method, and the noise has little effect on it. Therefore, the proposed algorithm has better performance in terms of noise resistance. Fig 10(b) presents the RMSE with varying the number of anchors. We can see RMSEs of all algorithms decrease with the increase of the number of anchors, this is due to the increase in the number of anchors, which increases more redundant information and improves the localization performance accordingly. In addition, since the FSICL algorithm combines the computing ability of the Chan algorithm and swarm search ability of the FA to locate UAVs, the proposed FSICL achieves the lowest RMSE compared with the other three algorithms. Clustering performance Connectivity. Fig 11(a) and 11(b) intuitively display the connectivity of UAVs at the speed of 1m/s after different iterations. We can see that the distribution of CMs after ten iterations is more balanced than the initial distribution and the communication burden of each CH is allocated more evenly. This is because we consider the node degree when selecting the CHs. The UAV with an appropriate number of node degree is more likely to be selected a CH, which leads to a certain distance between CHs. In addition, CMs will adjust their locations on the basis of their fitness values to automatically track the motion of CHs, which makes the distribution of UAVs more evenly.
Stability. Fig 12 shows the variance of the number of UAVs in clusters after different iterations with different speeds. The variance of clusters at time t is defined as: The smaller the variance, the more stable the number of CMs are in the cluster. We can see that variance is greater when speed is faster. This is because the high mobility of network UAVs leads to the faster updating of network topology and disconnection of communication links, resulting in more frequent cluster updates. The faster the speed, the more time it takes to achieve lower variance. When the moving speed of UAV is 1m/s, the swarm can stabilize faster than the other speeds, the faster the communication routing is stabilized. Fig 13 reflects the influence of the speed of UAV on the handover rate of CHs in the swarm. The handover rate of CHs is defined as the number of the CHs update in unit time divided by the total number of the network UAVs. With the continuous increase of the moving speeds of UAVs in the network, the handover rate is on the rise. This is because the high mobility of Since the proposed FSIAC algorithm comprehensively considers the firefly inspired movement mechanism that CMs are willing to track the CH in the cluster, the handover rate of the proposed FSIAC algorithm is lower than the other five clustering algorithms, which achieves the best stability of CHs.
LET. Fig 14 shows the average LET of different clustering algorithms when moving speeds of UAVs are 1m/s. The LET is the average of the time from the connection of the link to the disconnection of the link between the CH and the CMs. The longer the LET, the more stable the intra-cluster communication. We can see from this figure that with the increase of the UAV number, the average LET of the above five algorithms decreases. This is because the network topology changes are more and more frequent due to the increase of the moving UAVs, and the average LET general decreases. With the change of the UAV number, the proposed FSIAC algorithm has the longest LET compared with the LIC, HCC, WCA, EMASS and ICRA algorithms. This is because the proposed FSIAC algorithm considers the link survival probability in fitness function for CH selection, and CMs will adjust their locations to automatically track the CH, which makes the LET longer and intra-communication more stable.
Node lifetime. The node lifetime is defined as the time for a node from being active to inactive, and each UAV is regard as a node in the network. When a clustering scheme executes, the fitness values of CHs and CMs decrease over time and the node is no longer active after it runs out of battery power. As indicated in Fig 15, the minimum node lifetime decreases when more UAVs are introduced to the network. This is because when the UAV swarm is larger, the changes of the network topology become more frequent, which increases the cost of maintaining the topology and energy consumption of the CHs, thus shortening the lifetime of the UAV swarm. Regardless of the increase or decrease of UAV number, our proposed FSIAC algorithm achieves the longest node lifetime compared with the other five algorithms. This is because we consider a more reasonable fitness function to enable timely switching between CHs and CMs, leading to the extension of the entire network lifetime.

Summary
The summary and comparison of the proposed FSICL and FSIAC algorithms with the other algorithms are listed in Tables 2 and 3. We can see that the proposed FSICL algorithm achieves the fastest convergence speed and highest localization accuracy, and the proposed FSIAC algorithm achieves the highest stability of clusters, longest LET and longest node lifetime.

Conclusion
The FANET is a special application of the MANET in the field of UAV. It not only has the characteristics of centerless and easy to deploy, but also faces the more severe problem of highspeed mobile UAVs, which brings instability to the topology and communication. In this paper, we propose novel FSICL and FSIAC algorithms for FANETs that use the FA to locate UAVs, complete CH selection and cluster formation. The FSICL first combines the FA and Chan algorithm to cooperative locate UAVs based on UWB TDOA technique, which narrows the search zone of the FA based on the initial solution obtained by the Chan algorithm. Then the FSIAC algorithm uses a more appropriate objective function which consists of link survival probability, node degree-difference, average distance and residual energy, and take it as the light intensity of a firefly. The FA finally is used again for CH selection and cluster formation, enabling UAVs to spontaneously cluster around their CHs by tracking them.
The proposed FSICL has been tested in terms of location estimation, convergence, and RMSE of localization. Meanwhile, the proposed FSIAC has been tested in terms of distribution of UAVs, stability of clusters, intra-cluster communication, and node lifetime. The results show the proposed FSICL algorithm effectively achieves the higher localization accuracy in less time, and with the help of the FSICL, the proposed FSIAC algorithm achieves higher stability of clusters, longer LET and longer node lifetime, all of which improve communication performance of the FANET. With the salient performance and technical merits, the proposed FSICL and FSIAC algorithms may serve as practical solutions for indoor FANETs.
With the high localization accuracy of the FSICL algorithm, the verifications of indoor UAVs applications can be well supported by only carrying UWB devices, but it is difficult to deploy UWB anchors in actual tasks. Therefore, in the future, we will study semantics-aware visual localization and the engineering design of the Hello message to realize the real application of the proposed FSIAC algorithm.